import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailItem extends StatefulWidget {
  ///左侧标签
  final String label;

  ///左侧标签名称
  final String tagName;

  ///右侧内容
  final String content;

  final String? contentColor;

  ///左侧标签样式
  final LabelStyle labelStyle;

  ///右侧标签样式
  final ContentStyle contentStyle;

  ///点击右侧内容回调
  final VoidCallback? onTap;

  ///输入框回调
  final Function(String value)? onInput;

  ///详情item 左label右内容
  const DetailItem({super.key, this.label = '', this.content = '', this.tagName = '', this.labelStyle = LabelStyle.normal, this.contentStyle = ContentStyle.normal, this.onTap, this.onInput, this.contentColor});

  @override
  State<StatefulWidget> createState() {
    return _DetailItemState();
  }
}

class _DetailItemState extends State<DetailItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 10.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [_getLabel(), _getContent()],
      ),
    );
  }

  ///获取标签样式widget
  Widget _getLabel() {
    switch (widget.labelStyle) {
      case LabelStyle.normal:
        return Text(widget.label, style: setTextStyle(14, FontWeight.w300, Color(0xff3d3d3d)));
      case LabelStyle.title:
        return Text(widget.label, style: setTextStyle(14, FontWeight.w700, ThemeConfig.mainTextColor));
      case LabelStyle.labelTitleRed:
        return Row(
          children: [
            Container(
              padding: const EdgeInsets.only(left: 5, right: 5, top: 3, bottom: 3),
              margin: const EdgeInsets.only(right: 5),
              decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(3)), color: ThemeConfig.themeColor),
              child: Text(
                widget.tagName,
                style: setTextStyle(9, FontWeight.normal, Colors.white),
              ),
            ),
            Text(widget.label, style: setTextStyle(14, FontWeight.w300, ThemeConfig.mainTextColor))
          ],
        );
      case LabelStyle.labelTitleYellow:
        return Row(
          children: [
            Container(
              padding: const EdgeInsets.only(left: 5, right: 5, top: 3, bottom: 3),
              margin: const EdgeInsets.only(right: 5),
              decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(3)), color: ThemeConfig.addCollectColor),
              child: Text(
                widget.tagName,
                style: setTextStyle(9, FontWeight.normal, Colors.white),
              ),
            ),
            Text(widget.label, style: setTextStyle(14, FontWeight.w300, ThemeConfig.mainTextColor))
          ],
        );
    }
  }

  ///获取内容样式widget
  Widget _getContent() {
    switch (widget.contentStyle) {
      case ContentStyle.normal:
        return Text(widget.content, style: setTextStyle(13, FontWeight.w500, Color(0xff3d3d3d)));
      case ContentStyle.nextMore:
        return BaseInteractive(
          onClick: widget.onTap,
          childWidget: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Text(
                widget.content,
                style: setTextStyle(13, FontWeight.w500, widget.contentColor == null ? const Color(0xffe86d59) : Tools.fromHex(widget.contentColor!)),
              ),
              Icon(
                Icons.navigate_next,
                color: widget.contentColor == null ? const Color(0xffe86d59) : Tools.fromHex(widget.contentColor!),
                size: 14,
              )
            ],
          ),
        );
      case ContentStyle.expandCollapse:
        return BaseInteractive(
          onClick: () {
            widget.onTap;
          },
          childWidget: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Text(widget.content, style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor)),
              Icon(
                Icons.expand_more,
                size: 14,
              )
            ],
          ),
        );
      case ContentStyle.order:
        return BaseInteractive(
          onClick: widget.onTap,
          childWidget: Text(widget.content, style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor)),
        );
      case ContentStyle.title:
        return Text(widget.content, style: setTextStyle(13, FontWeight.w700, ThemeConfig.mainTextColor));
      case ContentStyle.discount:
        return Text(widget.content, style: setTextStyle(13, FontWeight.w400, ThemeConfig.themeColor));
      case ContentStyle.discountTotal:
        return Text(widget.content, style: setTextStyle(13, FontWeight.w700, ThemeConfig.themeColor));
    }
  }
}

///标签样式
enum LabelStyle {
  ///普通
  normal,

  ///标题（加粗）
  title,

  ///带标签标题(红)
  labelTitleRed,

  ///带标签标题(黄)
  labelTitleYellow
}

///内容样式
enum ContentStyle {
  ///普通
  normal,

  ///点击更多
  nextMore,

  ///展开、收起
  expandCollapse,

  ///订单内容
  order,

  ///标题(加粗)
  title,

  ///折扣内容
  discount,

  ///折扣总和
  discountTotal,
}
